package com.lesserpand.springcloudalibabaprovider.securityoauththree.service.impl;

import com.lesserpand.springcloudalibabaprovider.securityoauththree.dao.SecurityOauthThreeDAO;
import com.lesserpand.springcloudalibabaprovider.securityoauththree.entity.SecurityOauthThreeDO;
import com.lesserpand.springcloudalibabaprovider.securityoauththree.entity.bo.SecurityOauthThreeBO;
import com.lesserpand.springcloudalibabaprovider.securityoauththree.entity.dto.SecurityOauthThreeDTO;
import com.lesserpand.springcloudalibabaprovider.securityoauththree.service.SecurityOauthThreeService;
import com.lesserpand.springcloudalibabaprovider.user.controller.UserController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author bailuo
 * @version 2.0
 * @Description TODO
 * @Date Created in 2018/12/10 15:29
 */
@Service("securityOauthThreeService")
public class SecurityOauthThreeServiceImpl implements SecurityOauthThreeService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private SecurityOauthThreeDAO securityOauthThreeDAO;

    @Override
    public SecurityOauthThreeBO save(SecurityOauthThreeDTO securityOauthThreeDTO) {
        String clientId = "story" + UUID.randomUUID().toString();
        String security = "security" + UUID.randomUUID().toString();
        SecurityOauthThreeDO securityOauthThreeDO = new SecurityOauthThreeDO();
        BeanUtils.copyProperties(securityOauthThreeDTO, securityOauthThreeDO);
        securityOauthThreeDO.setClientId(clientId);
        securityOauthThreeDO.setSecurity(security);
        try {
            securityOauthThreeDAO.save(securityOauthThreeDO);
        } catch (Exception e) {
            LOGGER.error("新增失败", e);
        }
        SecurityOauthThreeBO securityOauthThreeBO = new SecurityOauthThreeBO();
        BeanUtils.copyProperties(securityOauthThreeDO, securityOauthThreeBO);
        return securityOauthThreeBO;
    }
}
